package com.idc.common.log;

import java.text.Normalizer;
import java.util.Arrays;
import java.util.List;

import ch.qos.logback.classic.pattern.ClassicConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;

/**
 * @author Administrator
 */
public class LogFilter extends ClassicConverter {

	private static List<String> list = Arrays.asList("%0a", "%0A", "%0d", "%0D", "\r", "\n");

    @Override
    public String convert(ILoggingEvent event) {
        return convertLog(event.getFormattedMessage());
    }

    /**
     * 特殊字符替换
     *
     * @param logs
     * @return
     */
    public static String convertLog(String logs) {
        String converted = Normalizer.normalize(logs, Normalizer.Form.NFKC);
        for (String s : list) {
            converted = converted.replace(s, "");
        }
        return converted;
    }
}